//
//  YZMDayGainComCell.m
//  YZMicroStock
//
//  Created by apple on 17/4/1.
//  Copyright © 2017年 cqjr. All rights reserved.
//

#import "YZMDayGainComCell.h"
#import "NSNumber+Utils.h"

@interface YZMDayGainComCell ()
@property (nonatomic, strong) UIImageView *rankImageView;
@property (nonatomic, strong) UILabel *rankLabel;
@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) UILabel *numberLabel;

@end

@implementation YZMDayGainComCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if (self= [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self createObj];
        self.rightMargin = 10.0;
        self.leftMargin = 10.0;
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return self;
}

-(void)createObj{
    
    
    UIView *firstView = [UIView new];
    [self.contentView addSubview:firstView];
    [firstView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.bottom.left.equalTo(self.contentView);
        make.width.mas_equalTo(ScreenWidth*0.25);
    }];
    
    self.rankImageView = [UIImageView new];
    [firstView addSubview:self.rankImageView];
    [self.rankImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(firstView).offset(12);
        make.centerX.equalTo(firstView);
    }];
    
    self.rankLabel = [YZMAppStyle labelWithMediumWhite];
    self.rankLabel.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:self.rankLabel];
    [self.rankLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(firstView).offset(20);
        make.centerX.equalTo(firstView);
    }];
    
    self.nameLabel = [YZMAppStyle labelWithMediumWhite];
    self.nameLabel.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:self.nameLabel];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.rankLabel);
        make.width.mas_equalTo(ScreenWidth*0.35);
        make.left.equalTo(firstView.mas_right);
    }];
    
    self.numberLabel = [YZMAppStyle labelWithMediumGray];
    self.numberLabel.textAlignment = NSTextAlignmentRight;
    [self.contentView addSubview:self.numberLabel];
    self.numberLabel.textColor = [YZMAppStyle colorForRiseText];
    [self.numberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.nameLabel);
        make.width.mas_equalTo(ScreenWidth*0.33);
        make.right.equalTo(self.mas_right).offset(-ScreenWidth*0.07);
    }];
    
    if (iPhone4 || iPhone5) {
        self.nameLabel.font = [YZMAppStyle fontWithSize:11];
        self.numberLabel.font = [YZMAppStyle fontWithSize:11];
    }
}

-(void)setIndexForImgageView:(NSInteger )indexForImgageView{
    
    _indexForImgageView = indexForImgageView;
    if (indexForImgageView<=2) {
        
        [self.rankImageView setImage:[UIImage imageNamed:[NSString stringWithFormat:@"Image_rank_cell%@",@(indexForImgageView+1)]]];
        self.rankLabel.hidden = YES;
        
    }else{
        
        self.rankImageView.hidden = YES;
        self.rankLabel.text = [NSString stringWithFormat:@"%@",@(indexForImgageView+1)];
    }
}

-(void)setGainModel:(YZMUserGainModel *)gainModel{
    
    _gainModel = gainModel;
    _nameLabel.text = gainModel.userName;
    _numberLabel.text  = [@(gainModel.money).r2fString stringByAppendingString:@"元"];
}

@end
